#ifndef MYTCPSERVER_H
#define MYTCPSERVER_H

#include <QTcpServer>
#include <QDebug>
#include <QByteArray>
#include "myclientsocket.h"
#include "databaseclass.h"
#include <QThread>
//#include "threadhandle.h"

class TcpPloyee
{
public:
    TcpPloyee(): TcpID() {}
    TcpPloyee( const QString &devName, const QString&surIP)
        : TcpID(devName), TcpIp(surIP)
    {}
    QString devName() const { return TcpID; }
    QString surIP() const { return TcpIp; }
private:
    QString TcpID;
    QString TcpIp;
};

class myTcpServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit myTcpServer(databaseClass *db,QObject *parent = 0);
    void SendData(int clientID,QByteArray data);
     QMap<QString,tcpInfo> *tcpSocketMap;//设备列表
     databaseClass *mydb;
private:
    QMap<int,myClientSocket *> *ClientSocketList;
    //QList<myClientSocket *> ClientSocketList;
    //QList<int> ClientSocketID;
    //QTimer *Server_timer;
    //bool Server_flag;
protected:
    void incomingConnection(int handle);
    
signals:
    void ClientReadData(int clientID,QString IP,int Port,QByteArray data);
    void ClientConnect(int clientID,QString IP,int Port);
    void ClientDisConnect(int clientID,QString IP,int Port);
    void openDoorSend(QString data);
  //  void stopMyClientTimer();
    
private slots:
    void ReadData(int clientID,QString IP,int Port,QByteArray data);
    void DisConnect(int clientID,QString IP,int Port);
    //void LinkTimeOut();
public slots:
    void OpenDoor(QString TcpID,QString flag,QString door,QString send_str);
    //void tcpMap_Link(int uid);
    //void socketMap_Link();
    void socketMap_Clear(QString ip);
    void tcpSocketDisconnect(QString TcpID);
    //void tcpSocketConnect(QString dev_id,QString dev_ip,int port,tcpInfo Info);
    void tcpSocketConnect(QString dev_id,QString dev_ip,tcpInfo Info);
    //void init();
    void openDoorReadData(QString);
};

#endif // MYTCPSERVER_H
